package ru.amse.stroganova.ui.action;

import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.AbstractButton;

/**
 * 
 * This class provides synchronization mechanism for different buttons,
 * constructed, using this action.
 * 
 * @author Dasha Stroganova
 * 
 */
public abstract class ToggleAction extends AbstractAction {

	private List<AbstractButton> buttons = new ArrayList<AbstractButton>();
	
	/**
	 * Defines an <code>Action</code> object with the specified description
	 * string and a default icon.
	 * 
	 * @param s
	 *            name
	 */
	public ToggleAction(String s) {
		super(s);
	}

	/**
	 * Adds button to the list of users.
	 * 
	 * @param button
	 *            button
	 */
	public void addButton(AbstractButton button) {
		buttons.add(button);
	}

	public void actionPerformed(ActionEvent e) {
		for (AbstractButton ab : buttons) {
			ab.setSelected(true);
		}
	}

}
